package com.shop2cn.iapi.coupon.testcase.old;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.mysql.fabric.xmlrpc.base.Array;
import com.shop2cn.iapi.coupon.parameter.UpdateCancelFlagBean;
import com.shop2cn.iapi.coupon.service.UpdateCancelFlagCall;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.couponvirtualrecord;
import com.ymttest.database.sqlwapper.couponvirtualrecordWapper;
//import com.ymttest.database.model.couponvirtualrecord;
//import com.ymttest.database.sqlwapper.YmtCouponActivityWapper;
import com.ymttest.utils.TestDataManager;

@TestSuite
public class Ts_UpdateCancelFlag {
	private static UpdateCancelFlagBean UpdateCancelFlagBean;
	private static UpdateCancelFlagCall UpdateCancelFlagCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取需要核销的虚拟券用例");
	}

	@Before
	public void caseUp() {
		UpdateCancelFlagBean=new UpdateCancelFlagBean();
		UpdateCancelFlagCall=new UpdateCancelFlagCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(UpdateCancelFlagCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateCancelFlag_001() {
		Logger.start(true,"更新核销标记)");
		try {
			
			List<String> list=new ArrayList();
			List<couponvirtualrecord> ra=new couponvirtualrecordWapper().selectTop3couponvirtualrecord();
			for(int i=0;i<ra.size();i++)
			{
				couponvirtualrecord newcouponvirtualrecord=ra.get(i);
				newcouponvirtualrecord.setIsUsed(true);
				newcouponvirtualrecord.setIsCancel(false);
				newcouponvirtualrecord.setUpdateTime(new Date());
				new couponvirtualrecordWapper().updateByPrimaryKey(newcouponvirtualrecord);
				list.add(newcouponvirtualrecord.getVirtualCode());
			}
			
			UpdateCancelFlagBean.setVirtualCouponCodeList(list);
			UpdateCancelFlagCall.setData(UpdateCancelFlagBean);
			UpdateCancelFlagCall.callService();
			
			Logger.verifyEquals("0", UpdateCancelFlagCall.getStatusCode1(), "验证返回Code");
		    Logger.verifyEquals("操作成功！",
		        		UpdateCancelFlagCall.getMessage(), "验证返回Message");

		    List<couponvirtualrecord> newcouponvirtualrecord=new couponvirtualrecordWapper().selectTop3couponvirtualrecord();
			for(int i=0;i<ra.size();i++)
			{
				couponvirtualrecord newro=newcouponvirtualrecord.get(i);
				Logger.verifyEquals(true, newro.getIsCancel(), "验证数据库couponvirtualrecord字段IsCancel");
				Logger.verifyEquals(true, newro.getIsUsed(), "验证数据库couponvirtualrecord字段IsUsed");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public String GetNowDate(){     
	    String temp_str="";     
	    Date dt = new Date();     
	    //最后的aa表示“上午”或“下午”    HH表示24小时制    如果换成hh表示12小时制     
	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");     
	    temp_str=sdf.format(dt);     
	    return temp_str;     
	}  
}
